package org.lanqiao.ssm.common.push;

import cn.jpush.api.JPushClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification;

/**
 * 
 * @Title: JpushHelper.java
 * @Package org.lanqiao.ssm.common.push
 * @Description:极光推送推送例子
 * @author 刘伟 15818570028@163.com
 * @date 2016年11月8日 下午1:40:34
 * @version V1.0
 */
public class JpushHelper {

	public static JPushClient jpushClient;
	static {
		jpushClient = new JPushClient("4a37b3702e086b6621281dbc", "9a57b2c0fe34e58f176d0d4b");
	}

	/**
	 * @see http://docs.jiguang.cn/jpush/server/3rd/java_sdk/
	 * @Title: buildPushObject_all_all_alert
	 * @Description:构造所有平台所有标签的通知
	 * @param msg
	 * @return
	 */
	public static PushPayload buildPushObject_all_all_alert(String msg) {
		return PushPayload.alertAll(msg);
	}
	/**
	 * 
	 * @Title: buildPushObject_all_all_alert
	 * @Description:构造所有平台指定别名的通知
	 * @param msg
	 * 
	 * @return
	 */
	public static PushPayload buildPushObject_all_alias_alert(String alias, String msg) {
		return PushPayload.newBuilder().setPlatform(Platform.all()).setAudience(Audience.alias(alias))
				.setNotification(Notification.alert(msg)).build();
	}
	/**
	 * 
	 * @Title: buildPushObject_all_all_alert
	 * @Description:构造android平台指定别名的通知
	 * @param msg
	 * @return
	 */
	public static PushPayload buildPushObject_android_tag_alertWithTitle(String tag, String msg, String title) {
		return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.tag(tag))
				.setNotification(Notification.android(msg, title, null)).build();
	}

	/**
	 * 
	 * @Title: main
	 * @Description:测试入口
	 * @param args
	 * @throws APIConnectionException
	 * @throws APIRequestException
	 */
	public static void main(String[] args) throws APIConnectionException, APIRequestException {
		/*
		 * PushResult result =
		 * jpushClient.sendPush(buildPushObject_all_all_alert("123"));
		 * 
		 * 
		 * System.out.println(result);
		 */
		PushResult sendAndroidMessageWithAlias = jpushClient.sendAndroidMessageWithAlias("你好", "我是温海金", "15818570028");
		System.out.println(sendAndroidMessageWithAlias);

		PushPayload payload = buildPushObject_all_all_alert("我是谭园");
		jpushClient.sendPush(payload);

	}
}
